package com.srv.common;

import java.util.HashMap;
import java.util.Map;
import com.srv.util.ObjectField;
import com.srv.util.ObjectFieldDBType;
import com.srv.util.StringUtil;

public class TravelField implements ObjectField {
	
	private static Map<String, TravelField> map = new HashMap<String, TravelField>();
	
	public static final TravelField PID = new TravelField("PID", ObjectFieldDBType.LONG, false, false);
	public static final TravelField ISDEL = new TravelField("ISDEL", ObjectFieldDBType.INT, true, false);
	public static final TravelField CREATETIME = new TravelField("CREATE_TIME", ObjectFieldDBType.TIMESTAMP, true, false);
	public static final TravelField UPDATETIME = new TravelField("UPDATE_TIME", ObjectFieldDBType.TIMESTAMP, true, false);
	
	public static final TravelField TRAVELID = new TravelField("TRAVEL_ID", ObjectFieldDBType.STRING, false, true);
	
	public static final TravelField TITLE = new TravelField("TITLE", ObjectFieldDBType.STRING, true, false);
	
	public static final TravelField STATUS = new TravelField("STATUS", ObjectFieldDBType.INT, true, false);
	
	public static final TravelField FINISHTIME = new TravelField("FINISH_TIME", ObjectFieldDBType.TIMESTAMP, true, false);
	
	public static final TravelField FAVORNUM = new TravelField("FAVOR_NUM", ObjectFieldDBType.LONG, true, false);
	
	public static final TravelField DOWNLOADNUM = new TravelField("DOWNLOAD_NUM", ObjectFieldDBType.LONG, true, false);
	
	public static final TravelField REPUBNUM = new TravelField("REPUB_NUM", ObjectFieldDBType.LONG, true, false);
	
	private String column;
    private ObjectFieldDBType type;
    private boolean modify = false;
    private boolean uniquene = false;
    
    public TravelField(String cn, ObjectFieldDBType type, boolean modify, boolean uniquene) {
    	this.column = cn;
        this.type = type;
        this.modify = modify;
        this.uniquene = uniquene;

        map.put(this.column, this);
    }
    
    public String getColumn() {
        return column;
    }

    public ObjectFieldDBType getType() {
        return type;
    }

    public boolean isModify() {
        return modify;
    }

    public boolean isUniquene() {
        return uniquene;
    }

    public int hashCode() {
        return column.hashCode();
    }
    
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof TravelField)) {
            return false;
        }

        return column.equalsIgnoreCase(((TravelField) obj).getColumn());
    }
    
    public static TravelField getByCode(String c) {
        if (StringUtil.isEmpty(c)) {
            return null;
        }

        return map.get(c.toLowerCase());
    }
}
